//
//  PolygonShape.m
//  Assignment2A
//
//  Created by George Tso on 10/15/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PolygonShape.h"
@implementation PolygonShape

@synthesize numberOfSides;
@synthesize minimumNumberOfSides;
@synthesize maximumNumberOfSides;
@synthesize angleInDegrees;
@synthesize angleInRadians;
@synthesize name;

- (void)setNumberOfSIdes:(int)s {
	if(s <= minimumNumberOfSides)
		NSLog(@"Invalid number of sides: %d is smaller than the minimum of %d allowed", s, minimumNumberOfSides);
	else if(s >= maximumNumberOfSides)
		NSLog(@"Invalid number of sides: %d is greater than the maximum of %d allowed", s, maximumNumberOfSides);
	else
		self.numberOfSides = s;
}

- (id)init {
	[super init];
	[self initWithNumberOfSides:5 minimumNumberOfSides:3 maximumNumberOfSides:10];
	return self;
}

- (id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min 
	   maximumNumberOfSides:(int)max {
	[super init];
	self.numberOfSides = sides;
	self.minimumNumberOfSides = min;
	self.maximumNumberOfSides = max;
	return self;
}

- (float)angleInDegrees {
	return (180 * (self.numberOfSides - 2) / self.numberOfSides);
}

- (float)angleInRadians {
	return [self angleInDegrees] * M_PI / 180.0;
}

- (NSString *)name {
	NSString *tmp = [[[NSString alloc] initWithFormat:@"%d", numberOfSides] autorelease];
	switch (numberOfSides) {
		case 3:
			return (@"Triangle");
			break;
		case 4:
			return (@"Square");
			break;
		default:
			return tmp;
			break;
	}
}


- (NSString *)description {
	NSString *out = [[[NSString alloc] initWithFormat:@"Hi I'm a %d-sided polygon (aka a %@), with angles of %d degrees (%f radians)", self.numberOfSides, self.name, (int)[self angleInDegrees], [self angleInRadians]] autorelease];
	NSLog(@"%@", out);
	return out;
}

- (void)dealloc {
	[super dealloc];
	NSLog(@"dealloc is called here");
}

@end
